package org.harsh.transmission.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import org.harsh.transmission.domain.TransRecvmsg;
import org.harsh.transmission.service.ITransRecvmsgService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息接收Controller
 * 
 * @author liuhaibo
 * @date 2024-08-25
 */
@Controller
@RequestMapping("/transmission/recvmsg")
public class TransRecvmsgController extends BaseController
{
    private String prefix = "transmission/recvmsg";

    @Autowired
    private ITransRecvmsgService transRecvmsgService;

    @RequiresPermissions("transmission:recvmsg:view")
    @GetMapping()
    public String recvmsg()
    {
        return prefix + "/recvmsg";
    }

    /**
     * 查询消息接收列表
     */
    @RequiresPermissions("transmission:recvmsg:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TransRecvmsg transRecvmsg)
    {
        startPage();
        List<TransRecvmsg> list = transRecvmsgService.selectTransRecvmsgList(transRecvmsg);
        return getDataTable(list);
    }

    /**
     * 导出消息接收列表
     */
    @RequiresPermissions("transmission:recvmsg:export")
    @Log(title = "消息接收", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TransRecvmsg transRecvmsg)
    {
        List<TransRecvmsg> list = transRecvmsgService.selectTransRecvmsgList(transRecvmsg);
        ExcelUtil<TransRecvmsg> util = new ExcelUtil<TransRecvmsg>(TransRecvmsg.class);
        return util.exportExcel(list, "消息接收数据");
    }

    /**
     * 新增消息接收
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存消息接收
     */
    @RequiresPermissions("transmission:recvmsg:add")
    @Log(title = "消息接收", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TransRecvmsg transRecvmsg)
    {
        return toAjax(transRecvmsgService.insertTransRecvmsg(transRecvmsg));
    }

    /**
     * 修改消息接收
     */
    @RequiresPermissions("transmission:recvmsg:edit")
    @GetMapping("/edit/{recvMsgId}")
    public String edit(@PathVariable("recvMsgId") Long recvMsgId, ModelMap mmap)
    {
        TransRecvmsg transRecvmsg = transRecvmsgService.selectTransRecvmsgByRecvMsgId(recvMsgId);
        mmap.put("transRecvmsg", transRecvmsg);
        return prefix + "/edit";
    }

    /**
     * 修改保存消息接收
     */
    @RequiresPermissions("transmission:recvmsg:edit")
    @Log(title = "消息接收", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TransRecvmsg transRecvmsg)
    {
        return toAjax(transRecvmsgService.updateTransRecvmsg(transRecvmsg));
    }

    /**
     * 删除消息接收
     */
    @RequiresPermissions("transmission:recvmsg:remove")
    @Log(title = "消息接收", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(transRecvmsgService.deleteTransRecvmsgByRecvMsgIds(ids));
    }
}
